﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Douban.Core.Menus
{
    public class MenuManager : IMenuManager
    {
        private IList<MenuItem> _menuItems;

        public MenuManager()
        {
            _menuItems = new List<MenuItem>();
        }

        #region IMenuManager Members

        public void Add(MenuItem item)
        {
            _menuItems.Add(item);
            OnMenuChanged(MenuAction.Add, item);
        }

        public void Remove(MenuItem item)
        {
            _menuItems.Remove(item);
            OnMenuChanged(MenuAction.Remove, item);
        }

        public IEnumerable<MenuItem> GetMenuItems()
        {
            return _menuItems;
        }

        public void OnMenuChanged(MenuAction action, MenuItem menu)
        {
            if (MenuChanged != null)
                MenuChanged(this, new MenuChangedEventArgs(action, menu));
        }

        public event MenuChangedEventHandler MenuChanged;

        #endregion
    }
}
